package com.sheliduan.itlearning.blogger.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sheliduan.itlearning.blogger.model.vos.user.FindStuUserPageListReqVO;
import com.sheliduan.itlearning.common.aspect.ApiOperationLog;
import com.sheliduan.itlearning.common.domain.dos.UserBoughtCourseDO;
import com.sheliduan.itlearning.common.domain.dos.UserDO;
import com.sheliduan.itlearning.common.domain.mapper.ArticleCourseMapper;
import com.sheliduan.itlearning.common.domain.mapper.UserBoughtCourseMapper;
import com.sheliduan.itlearning.common.domain.mapper.UserMapper;
import com.sheliduan.itlearning.common.domain.mapper.VideoCourseMapper;
import com.sheliduan.itlearning.common.model.vos.IdReqVO;
import com.sheliduan.itlearning.common.utils.PageResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.stream.Collectors;

/**
 * @author: 断舍离
 * @date: 2025/4/16 21:12
 * @description:
 **/

@RestController
@RequestMapping("/blogger")
public class BloggerStuUserController {

    @Autowired
    private UserMapper userMapper;

    @Autowired
    private UserBoughtCourseMapper userBoughtCourseMapper;

    /*
     * 分页查询课程
     * */
    @PostMapping("/user/pageList")
    @ApiOperationLog(description = "该博主用户下的分页学员信息")
    public PageResponseData findStuUserPageList(@RequestBody @Validated FindStuUserPageListReqVO reqVO){
        Page<UserBoughtCourseDO> userBoughtCourseDOPage = userBoughtCourseMapper.selectPageList(reqVO.getCurrent(), reqVO.getSize(), reqVO.getUsername(), reqVO.getBloggerId(), reqVO.getStartDate(), reqVO.getEndDate());
        Page<UserDO> userDOPage = new Page<>(reqVO.getCurrent(), reqVO.getSize());
        userDOPage.setSize(userBoughtCourseDOPage.getSize());
        userDOPage.setTotal(userBoughtCourseDOPage.getTotal());
        userDOPage.setRecords(userBoughtCourseDOPage.getRecords().stream().map(e -> userMapper.selectById(e.getUserId())).collect(Collectors.toList()));
        return PageResponseData.success(userDOPage, userDOPage.getRecords());
    }
}
